import 'package:BeeApp/CarPage/CarOrderListPage01.dart';
import 'package:BeeApp/CarPage/CarOrderListPage02.dart';
import 'package:BeeApp/MainPage/MainToolPage.dart';
import 'package:flutter/material.dart';

class CarMainPage03 extends StatefulWidget {
  CarMainPage03({Key key}) : super(key: key);

  @override
  _CarMainPage03State createState() => _CarMainPage03State();
}

class _CarMainPage03State extends State<CarMainPage03> {
  TabController _controller;
  List tabs = ["已接单", "待送件"];
  List pages = [
    CarOrderListPage01(),
    CarOrderListPage02(),
  ];

  @override
  void initState() {
    super.initState();
    _controller = TabController(
      length: tabs.length,
      vsync: ScrollableState(),
    );

    // _controller.addListener(
    //   () {
    //     if (_controller.index.toDouble() == _controller.animation.value) {
    //       //赋值 并更新数据
    //       this.setState(() {
    //         print(_controller.index);
    //         if (_controller.index == 0) {
    //           print("全部订单");
    //         } else if (_controller.index == 1) {
    //           print("已处理订单");
    //         } else {
    //           print("未处理订单");
    //         }
    //       });
    //     }
    //   },
    // );
  }

  @override
  void dispose() {
    super.dispose();
    _controller?.removeListener(() {});
    _controller?.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(40),
        child: Material(
          color: Colors.white,
          child: TabBar(
              indicator: BoxDecoration(
                color: maincolor,
              ),
              labelColor: Colors.white,
              unselectedLabelColor: Colors.grey,
              controller: _controller,
              indicatorSize: TabBarIndicatorSize.tab,
              labelStyle: TextStyle(fontSize: setFontSize(30)),
              //生成Tab菜单
              tabs: tabs.map((e) => Tab(text: e)).toList()),
        ),
      ),
      body: TabBarView(
          controller: _controller,
          // children: pages.map((e) {
          //   //分别创建对应的Tab页面
          //   return OrderListPage01();
          // }).toList(),
          children: pages.map((e) => Tab(child: e)).toList()),
    );
  }
}
